﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Maticsoft.Common;

namespace Maticsoft.Web
{
    public partial class ShoppingCar : PageBaseMember
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Check();

            if (!IsPostBack)
            {
                BindCar();
            }
        }

        /// <summary>
        /// 绑定购物车
        /// </summary>
        protected void BindCar()
        {
            //BLL.ShoppingCar _ShoppingCarBLL = new BLL.ShoppingCar();
            //Model.ShoppingCar _ShoppingCarModel = _ShoppingCarBLL.GetShoppingCar();
            //if (_ShoppingCarModel.OitemList.Count > 0)
            //{
            //    Repeater1.DataSource = _ShoppingCarModel.OitemList;
            //    Repeater1.DataBind();

            //    productNum.InnerText = _ShoppingCarModel.Order.OitemNum.ToString();
            //    totalMoney.InnerText = "￥" + _ShoppingCarModel.Order.ProductPrice;
            //}
            BLL.ShoppingInfo carBLL = new BLL.ShoppingInfo();
            DataSet ds = carBLL.GetListView("UserId=" + this.UserId + " and IsActive=1");
            Repeater1.DataSource = ds.Tables[0].DefaultView;
            Repeater1.DataBind();

            int num = 0;
            decimal total = 0;
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    num += DigitHelper.GetInt32(dr["ProductNum"]);
                    total += DigitHelper.GetDecimal(dr["SalePrice"]) * DigitHelper.GetInt32(dr["ProductNum"]);
                }

                productNum.InnerText = num.ToString();
                totalMoney.InnerText = "￥" + total.ToString("f2");
            }
        }
    }
}